import { Component, Label, Node, Sprite, tween, Vec3, _decorator, UIOpacity, UITransform, size } from "cc";

const {ccclass, property} = _decorator;
@ccclass('TipMg')
export class TipMg extends Component {
    @property(Node)
    desTxt: Node = null;

    @property({ type: Node })
    bgSpr: Node

    onLoad () {
        
    }

    start () {

    }

    public setDesData(res)
    {
        this.node.active = true;
        this.desTxt.getComponent(Label).string = res;

        function fn(){
            if (this.node)
            {
                let width = this.desTxt.getComponent(UITransform).contentSize.width + 100
                width = width < 342?342:width
                width = width > 1000?1000:width
                this.bgSpr.getComponent(UITransform).setContentSize(width, 64);
            }
        }
        this.scheduleOnce(fn, 0)

        this.bgSpr.setScale(0.4,0.4,1);
        tween()
            .target(this.bgSpr)
            .to(0.07,{ scale: new Vec3(1.2, 1.2, 1) })
            .to(0.1,{ scale: new Vec3(0.6, 0.6, 1) })
            .to(0.1,{ scale: new Vec3(1.1, 1.1, 1) })
            .to(0.05,{ scale: new Vec3(0.8, 0.8, 1) })
            .to(0.05,{ scale: new Vec3(1.0, 1.0, 1) })
            .to(0.05,{ scale: new Vec3(0.9, 0.9, 1) })
            .to(0.05,{ scale: new Vec3(1.0, 1.0, 1) })

            .delay(1.0)
            .by(0.4, { position: new Vec3(0, 160, 0) })
            .call(() => {
                this.node.destroy();
            })
            .start()

        tween(this.bgSpr.getComponent(UIOpacity))
            .delay(1.4)
            .to(0.4, { opacity: 0 }).start()

    }
        
}
